package com.itheima.homework.homework7;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collector;

/*
现获取到一段文本，如下：
wo ai heima wo ai java wo yao hao hao xue xi java
单词间以空格分隔，请编写程序统计这段文本中每个单词出现的次数。输出格式如下：
xi(1)java(2)yao(1)hao(2)wo(3)ai(2)heima(1)xue(1)
 */
public class Demo7 {
    public static void main(String[] args) {
        String  s="wo ai heima wo ai java wo yao hao hao xue xi java";
        String[] ss = s.split(" ");
        ArrayList<String> list=new ArrayList<>();
        Collections.addAll(list,ss);
        TreeSet<String> set=new TreeSet<>();
        Collections.addAll(set,ss);
        for (String s1 : set) {
            int count=0;
            for (String s2 : list) {
                if(s1.equals(s2)){
                    count++;
                }
            }
            System.out.println(s1+"("+count+")");
        }

    }
}
